package util;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
    //获取当前日期时间
    public static String getDate(){
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time=sdf.format(date);
        return time;
    }

    //获取当前年份
    public static String getYear(){
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy");
        String time=sdf.format(date);
        return time;
    }

    //查询总数
    public static Long getCountTotal(String sql,Object[] params) throws SQLException {
        QueryRunner runner=new QueryRunner(DataSourceUtil.getDataSource());
        Long count=runner.query(sql,new ScalarHandler<Long>(),params);
        return count;
    }

}
